$OpenBSD: patch-gettext-runtime_intl_dcigettext_c,v 1.7 2014/07/10 20:42:28 naddy Exp $
--- gettext-runtime/intl/dcigettext.c.orig	Tue Apr 15 03:52:10 2014
+++ gettext-runtime/intl/dcigettext.c	Tue Jul  8 23:49:09 2014
@@ -505,6 +505,7 @@ DCIGETTEXT (const char *domainname, const char *msgid1
   const char *localename;
 #endif
   size_t domainname_len;
+  size_t xdomainname_len;
 
   /* If no real MSGID is given return NULL.  */
   if (msgid1 == NULL)
@@ -625,6 +626,7 @@ DCIGETTEXT (const char *domainname, const char *msgid1
 	  /* We have a relative path.  Make it absolute now.  */
 	  size_t dirname_len = strlen (dirname) + 1;
 	  size_t path_max;
+	  size_t resolved_dirname_len;
 	  char *resolved_dirname;
 	  char *ret;
 
@@ -633,7 +635,8 @@ DCIGETTEXT (const char *domainname, const char *msgid1
 
 	  for (;;)
 	    {
-	      resolved_dirname = (char *) alloca (path_max + dirname_len);
+	      resolved_dirname_len = path_max + dirname_len;
+	      resolved_dirname = (char *) alloca (resolved_dirname_len);
 	      ADD_BLOCK (block_list, tmp_dirname);
 
 	      __set_errno (0);
@@ -650,7 +653,8 @@ DCIGETTEXT (const char *domainname, const char *msgid1
 	       error but simply return the default string.  */
 	    goto return_untranslated;
 
-	  stpcpy (stpcpy (strchr (resolved_dirname, '\0'), "/"), dirname);
+	  strlcat (resolved_dirname, "/", resolved_dirname_len);
+	  strlcat (resolved_dirname, dirname, resolved_dirname_len);
 	  dirname = resolved_dirname;
 	}
 #ifndef IN_LIBGLOCALE
@@ -668,13 +672,14 @@ DCIGETTEXT (const char *domainname, const char *msgid1
 #endif
 
   domainname_len = strlen (domainname);
-  xdomainname = (char *) alloca (strlen (categoryname)
-				 + domainname_len + 5);
+  xdomainname_len = strlen (categoryname) + domainname_len + 5;
+  xdomainname = (char *) alloca (xdomainname_len);
   ADD_BLOCK (block_list, xdomainname);
 
-  stpcpy ((char *) mempcpy (stpcpy (stpcpy (xdomainname, categoryname), "/"),
-			    domainname, domainname_len),
-	  ".mo");
+  strlcpy (xdomainname, categoryname, xdomainname_len);
+  strlcat (xdomainname, "/", xdomainname_len);
+  strlcat (xdomainname, domainname, xdomainname_len);
+  strlcat (xdomainname, ".mo", xdomainname_len);
 
   /* Creating working area.  */
   single_locale = (char *) alloca (strlen (categoryvalue) + 1);
@@ -772,13 +777,17 @@ DCIGETTEXT (const char *domainname, const char *msgid1
 		  /* Create a new entry and add it to the search tree.  */
 		  size_t msgid_len;
 		  size_t size;
+#ifdef HAVE_PER_THREAD_LOCALE
+		  size_t localename_len;
+#endif
 		  struct known_translation_t *newp;
 
 		  msgid_len = strlen (msgid1) + 1;
 		  size = offsetof (struct known_translation_t, msgid)
 			 + msgid_len + domainname_len + 1;
 #ifdef HAVE_PER_THREAD_LOCALE
-		  size += strlen (localename) + 1;
+		  localename_len = strlen (localename);
+		  size += localename_len + 1;
 #endif
 		  newp = (struct known_translation_t *) malloc (size);
 		  if (newp != NULL)
@@ -794,7 +803,7 @@ DCIGETTEXT (const char *domainname, const char *msgid1
 		      memcpy (new_domainname, domainname, domainname_len + 1);
 #ifdef HAVE_PER_THREAD_LOCALE
 		      new_localename = new_domainname + domainname_len + 1;
-		      strcpy (new_localename, localename);
+		      memcpy (new_localename, localename, localename_len + 1);
 #endif
 		      newp->domainname = new_domainname;
 		      newp->category = category;
